const newstoken = "newstoken";
const channel_KEY = "channel_KEY";
const newsHistoryList = "newsHistoryList";
// 封装保存token
export const setToken = (tokenObj) => {
  window.localStorage.setItem(newstoken, JSON.stringify(tokenObj));
};

// 封装获取token
export const getToken = () => {
  // return 拿到的token（obj）
  return JSON.parse(localStorage.getItem(newstoken));
};

// 封装删除token
export const removeToken = () => {
  localStorage.removeItem(newstoken);
};

// 存频道信息
export const setChannels = (list) => {
  window.localStorage.setItem(channel_KEY, JSON.stringify(list));
};

// 取频道信息
export const getChannels = () => {
  return JSON.parse(window.localStorage.getItem(channel_KEY));
};

// 删除频道信息
export const removeChannels = () => {
  window.localStorage.removeItem(channel_KEY);
};

// 存搜索信息
export const setHistory = (list) => {
  window.localStorage.setItem(newsHistoryList, JSON.stringify(list));
};

// 取搜索信息
export const getHistory = () => {
  return JSON.parse(window.localStorage.getItem(newsHistoryList));
};

// 删除搜索信息
export const removeHistory = () => {
  window.localStorage.removeItem(newsHistoryList);
};
